package com.zm.demo.core.leetcode;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import static java.lang.System.out;

/**
 * 字符串中的第一个唯一字符
 * @author zoum
 * @create 2020/1/9 15:16
 */
public class FirstUniqChar {


    public int firstUniqChar(String s) {
        if (s == null || s.length() == 0){
            return -1;
        }
        Map<Character,Byte> map = new HashMap<>();
        for (int i = 0; i < s.length(); i++) {
            Character _this = s.charAt(i);
            if (map.get(_this)== null){
                if (s.lastIndexOf(_this) == i){
                    return i;
                }else {
                    map.put(_this,Byte.MIN_VALUE);
                }
            }
        }
        return -1;
    }

    public static void main(String[]args){



        out.println(new FirstUniqChar().firstUniqChar("cc"));
    }
}
